﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.DataObject;
using System.Data;
using System.Data.SqlClient;
namespace DataAccess.BusinessObject
{
    public class BOption:Common.CDBase
    {
        public bool Add(OOption _OOption)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@OptionName",SqlDbType.NVarChar),
                                        new SqlParameter("@OptionValue",SqlDbType.NVarChar),
                                        new SqlParameter("@Description",SqlDbType.NVarChar),
                                        new SqlParameter("@PollID",SqlDbType.Int),
                                        new SqlParameter("@OptionParent",SqlDbType.Int)};
            sqlParam[0].Value = _OOption.OptionName;
            sqlParam[1].Value = _OOption.OptionValue;
            sqlParam[2].Value = _OOption.Description;
            sqlParam[3].Value = _OOption.PollID;
            sqlParam[4].Value = _OOption.OptionParent;
            return RunProcedure("sp_tblOption_add", sqlParam);
        }
        public bool Update(OOption _OOption)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@OptionID",SqlDbType.Int),
                                        new SqlParameter("@OptionName",SqlDbType.NVarChar),
                                        new SqlParameter("@OptionValue",SqlDbType.NVarChar),
                                        new SqlParameter("@Description",SqlDbType.NVarChar),
                                        new SqlParameter("@OptionParent",SqlDbType.Int)};
            sqlParam[0].Value = _OOption.OptionID;
            sqlParam[1].Value = _OOption.OptionName;
            sqlParam[2].Value = _OOption.OptionValue;
            sqlParam[3].Value = _OOption.Description;
            sqlParam[4].Value = _OOption.OptionParent;
            return RunProcedure("sp_tblOption_update", sqlParam);
        }
        public bool Vote(int OptionID)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@OptionID", SqlDbType.Int) };
            sqlParam[0].Value = OptionID;
            return RunProcedure("sp_tblOption_vote", sqlParam);
        }
        public IList<OOption> Get(int PollID)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@PollID", SqlDbType.Int) };
            sqlParam[0].Value = PollID;
            return Common.Common.ConvertTo<OOption>(RunProcedureGet("sp_tblOption_get", sqlParam));
        }
        public bool Delete(int OptionID)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@OptionID", SqlDbType.Int) };
            sqlParam[0].Value = OptionID;
            return RunProcedure("sp_tblOption_delete", sqlParam);
        }
        public IList<OOption> GetLastRecord()
        {
            SqlParameter[] sqlParam = { };
            return Common.Common.ConvertTo<OOption>(RunProcedureGet("sp_tblOption_getlastrecord", sqlParam));
        }
    }
}
